package com.qys.livesMall.navy.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qys.livesMall.navy.common.Constant;
import com.qys.livesMall.navy.dao.NavyTaskDetailDao;
import com.qys.livesMall.navy.mapper.NavyTaskDetailMapper;
import com.qys.livesMall.navy.model.entity.NavyTaskDetail;
import com.qys.livesMall.navy.service.NavyTaskDetailService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 水军任务表 服务实现类
 * </p>
 *
 * @author
 * @since 2023-07-11
 */
@Service
public class NavyTaskDetailDaoImpl extends ServiceImpl<NavyTaskDetailMapper, NavyTaskDetail> implements NavyTaskDetailDao {

    @Override
    public boolean existNoEnd(Long taskId) {
        LambdaQueryWrapper<NavyTaskDetail> qw=new LambdaQueryWrapper<>();
        qw.eq(NavyTaskDetail::getTaskId,taskId);
        qw.eq(NavyTaskDetail::getTaskStatus, Constant.TaskDetailStatus.NO_START);
        return count(qw)==0?false:true;
    }

    @Override
    public NavyTaskDetail getNextDetail(Long taskId) {
        LambdaQueryWrapper<NavyTaskDetail> qw=new LambdaQueryWrapper();
        qw.select(NavyTaskDetail::getId,NavyTaskDetail::getTaskId,NavyTaskDetail::getTaskStatus,NavyTaskDetail::getTaskType);
        qw.eq(NavyTaskDetail::getTaskId,taskId);
        qw.eq(NavyTaskDetail::getTaskStatus, Constant.TaskDetailStatus.NO_START);
        qw.orderByAsc(NavyTaskDetail::getSort);
        qw.last("limit 1");
        return getOne(qw);
    }

    @Override
    public List<NavyTaskDetail> getAllNoEnd(Long taskId) {
        LambdaQueryWrapper<NavyTaskDetail> qw=new LambdaQueryWrapper();
        qw.eq(NavyTaskDetail::getTaskId,taskId);
        qw.eq(NavyTaskDetail::getTaskStatus, Constant.TaskDetailStatus.NO_START);
        qw.orderByAsc(NavyTaskDetail::getSort);
        return list(qw);
    }
}
